home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / repeat.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  19.2 KB  |  486 lines

  1. *repeat.txt*    For Vim version 6.0.  Last change: 2001 Sep 13
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Repeating commands, Vim scripts and debugging            *repeating*
  8.  
  9. Chapter 26 of the user manual introduces repeating |usr_26.txt|.
  10.  
  11. 1. Single repeats    |single-repeat|
  12. 2. Multiple repeats    |multi-repeat|
  13. 3. Complex repeats    |complex-repeat|
  14. 4. Using Vim scripts    |using-scripts|
  15. 5. Debugging scripts    |debug-scripts|
  16.  
  17. ==============================================================================
  18. 1. Single repeats                    *single-repeat*
  19.  
  20.                             *.*
  21. .            Repeat last change, with count replaced with [count].
  22.             Also repeat a yank command, when the 'y' flag is
  23.             included in 'cpoptions'.
  24.  
  25. Simple changes can be repeated with the "." command.  Without a count, the
  26. count of the last change is used.  If you enter a count, it will replace the
  27. last one.  If the last change included a specification of a numbered register,
  28. the register number will be incremented.  See |undo-redo| for an example how
  29. to use this.  Note that when repeating a command that used a Visual selection,
  30. the same SIZE of area is used, see |visual-repeat|.
  31.  
  32.                             *@:*
  33. @:            Repeat last command-line [count] times.
  34.             {not available when compiled without the
  35.             |+cmdline_hist| feature}
  36.  
  37.  
  38. ==============================================================================
  39. 2. Multiple repeats                    *multi-repeat*
  40.  
  41.                         *:g* *:global* *E147* *E148*
  42. :[range]g[lobal]/{pattern}/[cmd]
  43.             Execute the Ex command [cmd] (default ":p") on the
  44.             lines within [range] where {pattern} matches.
  45.  
  46. :[range]g[lobal]!/{pattern}/[cmd]
  47.             Execute the Ex command [cmd] (default ":p") on the
  48.             lines within [range] where {pattern} does NOT match.
  49.  
  50.                             *:v* *:vglobal*
  51. :[range]v[global]/{pattern}/[cmd]
  52.             Same as :g!.
  53.  
  54. The global commands work by first scanning through the [range] lines and
  55. marking each line where a match occurs (for a multi-line pattern, only the
  56. start of the match matters).
  57. In a second scan the [cmd] is executed for each marked line with its line
  58. number prepended.  If a line is changed or deleted its mark disappears.
  59. The default for [range] is the whole buffer (1,$).  Use "CTRL-C" to interrupt
  60. the command.  If an error message is given for a line, the command for that
  61. line is aborted and the global command continues with the next matching line.
  62.  
  63. To repeat a non-Ex command, you can use the ":normal" command: >
  64.     :g/pat/normal {commands}
  65. Make sure that {commands} ends with a whole command, otherwise Vim will wait
  66. for you to type the rest of the command for each match.  The screen will not
  67. have been updated, so you don't know what you are doing.  See |:normal|.
  68.  
  69. The undo/redo command will undo/redo the whole global command at once.
  70. The previous context mark will only be set once (with "''" you go back to
  71. where the cursor was before the global command).
  72.  
  73. The global command sets both the last used search pattern and the last used
  74. substitute pattern (this is vi compatible).  This makes it easy to globally
  75. replace a string:
  76.     :g/pat/s//PAT/g
  77. This replaces all occurrences of "pat" with "PAT".  The same can be done with:
  78.     :%s/pat/PAT/g
  79. Which is two characters shorter!
  80.  
  81. ==============================================================================
  82. 3. Complex repeats                    *complex-repeat*
  83.  
  84.                             *q* *recording*
  85. q{0-9a-zA-Z"}        Record typed characters into register {0-9a-zA-Z"}
  86.             (uppercase to append).  The 'q' command is disabled
  87.             while executing a register, and it doesn't work inside
  88.             a mapping.  {Vi: no recording}
  89.  
  90. q            Stops recording.  (Implementation note: The 'q' that
  91.             stops recording is not stored in the register, unless
  92.             it was the result of a mapping)  {Vi: no recording}
  93.  
  94.                             *@*
  95. @{0-9a-z".=*}        Execute the contents of register {0-9a-z".=*} [count]
  96.             times.  Note that register '%' (name of the current
  97.             file) and '#' (name of the alternate file) cannot be
  98.             used.  For "@=" you are prompted to enter an
  99.             expression.  The result of the expression is then
  100.             executed.  See also |@:|.  {Vi: only named registers}
  101.  
  102.                             *@@*
  103. @@            Repeat the previous @{0-9a-z":*} [count] times.
  104.  
  105. :[addr]*{0-9a-z".=}                        *:@* *:star*
  106. :[addr]@{0-9a-z".=*}    Execute the contents of register {0-9a-z".=*} as an Ex
  107.             command.  First set cursor at line [addr] (default is
  108.             current line).  When the last line in the register does
  109.             not have a <CR> it will be added automatically when
  110.             the 'e' flag is present in 'cpoptions'.
  111.             Note that the ":*" command is only recognized when the
  112.             '*' flag is present in 'cpoptions'.  This is NOT the
  113.             default when 'nocompatible' is used.
  114.             For ":@=" the last used expression is used.  The
  115.             result of evaluating the expression is executed as an
  116.             Ex command.
  117.             Mappings are not recognized in these commands.
  118.             {Vi: only in some versions} Future: Will execute the
  119.             register for each line in the address range.
  120.  
  121.                             *:@:*
  122. :[addr]@:        Repeat last command-line.  First set cursor at line
  123.             [addr] (default is current line).  {not in Vi}
  124.  
  125.                             *:@@*
  126. :[addr]@@        Repeat the previous :@{0-9a-z"}.  First set cursor at
  127.             line [addr] (default is current line).  {Vi: only in
  128.             some versions}
  129.  
  130. ==============================================================================
  131. 4. Using Vim scripts                    *using-scripts*
  132.  
  133. For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
  134.  
  135.                     *:so* *:source* *load-vim-script*
  136. :so[urce] {file}    Read Ex commands from {file}.  These are commands that
  137.             start with a ":".
  138.  
  139. :so[urce]! {file}    Read Vim commands from {file}.  These are commands
  140.             that are executed from Normal mode, like you type
  141.             them.  {not in Vi}
  142.  
  143.                             *:ru* *:runtime*
  144. :ru[ntime][!] {file} ..
  145.             Read Ex commands from {file} in each directory given
  146.             by 'runtimepath'.  There is no error for non-existing
  147.             files.  Example: >
  148.                 :runtime syntax/c.vim
  149.  
  150. <            There can be multiple {file} arguments, separated by
  151.             spaces.  Each {file} is searched for in the first
  152.             directory from 'runtimepath', then in the second
  153.             directory, etc.  Use a backslash to include a space
  154.             inside {file} (although it's better not to use spaces
  155.             in file names, it causes trouble).
  156.  
  157.             When [!] is included, all found files are sourced.
  158.             When it is not included only the first found file is
  159.             sourced.
  160.  
  161.             When {file} contains wildcards it is expanded to all
  162.             matching files.  Example: >
  163.                 :runtime! plugin/*.vim
  164. <            This is what Vim uses to load the plugin files when
  165.             starting up. This similar command: >
  166.                 :runtime plugin/*.vim
  167. <            would source the first file only.
  168.  
  169.             When 'verbose' is one or higher, there is a message
  170.             when no file could be found.
  171.             When 'verbose' is two or higher, there is a message
  172.             about each searched file.
  173.             {not in Vi}
  174.  
  175. :scripte[ncoding] [encoding]        *:scripte* *:scriptencoding* *E167*
  176.             Specify the character encoding used in the script.
  177.             The following lines will be converted from [encoding]
  178.             to the value of the 'encoding' option, if they are
  179.             different.  Examples: >
  180.                 scriptencoding iso-8859-5
  181.                 scriptencoding cp932
  182. <
  183.             When [encoding] is empty, no conversion is done.  This
  184.             can be used to restrict conversion to a sequence of
  185.             lines: >
  186.                 scriptencoding euc-jp
  187.                 ... lines to be converted ...
  188.                 scriptencoding
  189.                 ... not converted ...
  190.  
  191. <            When conversion isn't supported by the system, there
  192.             is no error message and no conversion is done.
  193.  
  194.             Don't use "ucs-2" or "ucs-4", scripts cannot be in
  195.             these encodings (they would contain NUL bytes).
  196.  
  197.             When compiled without the |+multi_byte| feature this
  198.             command is ignored.
  199.             {not in Vi}
  200.  
  201.                         *:scrip* *:scriptnames*
  202. :scrip[tnames]        List all sourced script names, in the order they were
  203.             first sourced.  The number is used for the script ID
  204.             |<SID>|.
  205.             {not in Vi} {not available when compiled without the
  206.             |+eval| feature}
  207.  
  208.                         *:fini* *:finish* *E168*
  209. :fini[sh]        Stop sourcing a script.  Can only be used in a Vim
  210.             script file.  This is a quick way to skip the rest of
  211.             the file.
  212.             {not in Vi}
  213.  
  214. All commands and command sequences can be repeated by putting them in a named
  215. register and then executing it.  There are two ways to get the commands in the
  216. register:
  217. - Use the record command "q".  You type the commands once, and while they are
  218.   being executed they are stored in a register.  Easy, because you can see
  219.   what you are doing.  If you make a mistake, "p"ut the register into the
  220.   file, edit the command sequence, and then delete it into the register
  221.   again.  You can continue recording by appending to the register (use an
  222.   uppercase letter).
  223. - Delete or yank the command sequence into the register.
  224.  
  225. Often used command sequences can be put under a function key with the ':map'
  226. command.
  227.  
  228. An alternative is to put the commands in a file, and execute them with the
  229. ':source!' command.  Useful for long command sequences.  Can be combined with
  230. the ':map' command to put complicated commands under a function key.
  231.  
  232. The ':source' command reads Ex commands from a file line by line.  You will
  233. have to type any needed keyboard input.  The ':source!' command reads from a
  234. script file character by character, interpreting each character as if you
  235. typed it.
  236.  
  237. Example: When you give the ":!ls" command you get the |hit-enter| prompt.  If
  238. you ':source' a file with the line "!ls" in it, you will have to type the
  239. <Enter> yourself.  But if you ':source!' a file with the line ":!ls" in it,
  240. the next characters from that file are read until a <CR> is found.  You will
  241. not have to type <CR> yourself, unless ":!ls" was the last line in the file.
  242.  
  243. It is possible to put ':source[!]' commands in the script file, so you can
  244. make a top-down hierarchy of script files.  The ':source' command can be
  245. nested as deep as the number of files that can be opened at one time (about
  246. 15).  The ':source!' command can be nested up to 15 levels deep.
  247.  
  248. You can use the "<sfile>" string (literally, this is not a special key) inside
  249. of the sourced file, in places where a file name is expected.  It will be
  250. replaced by the file name of the sourced file.  For example, if you have a
  251. "other.vimrc" file in the same directory as your ".vimrc" file, you can source
  252. it from your ".vimrc" file with this command: >
  253.     :source <sfile>:h/other.vimrc
  254.  
  255. In script files terminal-dependent key codes are represented by
  256. terminal-independent two character codes.  This means that they can be used
  257. in the same way on different kinds of terminals.  The first character of a
  258. key code is 0x80 or 128, shown on the screen as "~@".  The second one can be
  259. found in the list |key-notation|.  Any of these codes can also be entered
  260. with CTRL-V followed by the three digit decimal code.  This does NOT work for
  261. the <t_xx> termcap codes, these can only be used in mappings.
  262.  
  263.                             *:source_crnl* *W15*
  264. MS-DOS, Win32 and OS/2: Files that are read with ":source" normally have
  265. <CR><NL> <EOL>s.  These always work.  If you are using a file with <NL> <EOL>s
  266. (for example, a file made on Unix), this will be recognized if 'fileformats'
  267. is not empty and the first line does not end in a <CR>.  This fails if the
  268. first line has something like ":map <F1> :help^M", where "^M" is a <CR>.  If
  269. the first line ends in a <CR>, but following ones don't, you will get an error
  270. message, because the <CR> from the first lines will be lost.
  271.  
  272. Macintosh: Files that are read with ":source" normally have <CR> <EOL>s.
  273. These always work.  If you are using a file with <NL> <EOL>s (for example, a
  274. file made on Unix), this will be recognized if 'fileformats' is not empty and
  275. the first line does not end in a <CR>.  Be careful not to use a file with <NL>
  276. linebreaks which has a <CR> in first line.
  277.  
  278. On other systems, Vim expects ":source"ed files to end in a <NL>.  These
  279. always work.  If you are using a file with <CR><NL> <EOL>s (for example, a
  280. file made on MS-DOS), all lines will have a trailing <CR>.  This may cause
  281. problems for some commands (e.g., mappings).  There is no automatic <EOL>
  282. detection, because it's common to start with a line that defines a mapping
  283. that ends in a <CR>, which will confuse the automaton.
  284.  
  285.                             *line-continuation*
  286. Long lines in a ":source"d Ex command script file can be split by inserting
  287. a line continuation symbol "\" (backslash) at the start of the next line.
  288. There can be white space before the backslash, which is ignored.
  289.  
  290. Example: the lines >
  291.     :set comments=sr:/*,mb:*,el:*/,
  292.              \://,
  293.              \b:#,
  294.              \:%,
  295.              \n:>,
  296.              \fb:-
  297. are interpreted as if they were given in one line:
  298.     :set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-
  299.  
  300. All leading whitespace characters in the line before a backslash are ignored.
  301. Note however that trailing whitespace in the line before it cannot be
  302. inserted freely; it depends on the position where a command is split up
  303. whether additional whitespace is allowed or not.
  304.  
  305. There is a problem with the ":append" and ":insert" commands: >
  306.    :1append
  307.    \asdf
  308.    .
  309. The backslash is seen as a line-continuation symbol, thus this results in the
  310. command: >
  311.    :1appendasdf
  312.    .
  313. To avoid this, add the 'C' flag to the 'cpoptions' option: >
  314.    :set cpo+=C
  315.    :1append
  316.    \asdf
  317.    .
  318.    :set cpo-=C
  319.  
  320. Rationale:
  321.     Most programs work with a trailing backslash to indicate line
  322.     continuation.  Using this in Vim would cause incompatibility with Vi.
  323.     For example for this Vi mapping: >
  324.         :map xx  asdf\
  325. <    Therefore the unusual leading backslash is used.
  326.  
  327. ==============================================================================
  328. 5. Debugging scripts                    *debug-scripts*
  329.  
  330. Besides the obvious messages that you can add to your scripts to find out what
  331. they are doing, Vim offers a debug mode.  This allows you to step through a
  332. sourced file or user function and set breakpoints.
  333.  
  334. NOTE: The debugging mode is far from perfect.  Debugging will have side
  335. effects on how Vim works.  You cannot use it to debug everything.  For
  336. example, the display is messed up by the debugging messages.
  337. {Vi does not have a debug mode}
  338.  
  339. An alternative to debug mode is setting the 'verbose' option.  With a bigger
  340. number it will give more verbose messages about what Vim is doing.
  341.  
  342.  
  343. STARTING DEBUG MODE                        *debug-mode*
  344.  
  345. To enter debugging mode use one of these methods:
  346. 1. Start Vim with the |-D| argument: >
  347.     vim -D file.txt
  348. <  Debugging will start as soon as the first vimrc file is sourced.  This is
  349.    useful to find out what is happening when Vim is starting up.  A side
  350.    effect is that Vim will switch the terminal mode before initialisations
  351.    have finished, with unpredictable results.
  352.    For a GUI-only version (Windows, Macintosh) the debugging will start as
  353.    soon as the GUI window has been opened.  To make this happen early, add a
  354.    ":gui" command in the vimrc file.
  355.                                 *:debug*
  356. 2. Run a command with ":debug" prepended.  Debugging will only be done while
  357.    this command executes.  Useful for debugging a specific script or user
  358.    function.  And for scripts and fuctions used by autocommands.  Example: >
  359.     :debug edit test.txt.gz
  360.  
  361. 3. Set a breakpoint in a sourced file or user function.  You could do this in
  362.    the command line: >
  363.     vim -c "breakadd file */explorer.vim" .
  364. <  This will run Vim and stop in the first line of the "explorer.vim" script.
  365.    Breakpoints can also be set while in debugging mode.
  366.  
  367. In debugging mode every executed command is displayed before it is executed.
  368. Comment lines, empty lines and lines that are not executed are skipped.  When
  369. a line contains two commands, separated by "|", each command will be displayed
  370. separately.
  371.  
  372.  
  373. DEBUG MODE
  374.  
  375. Once in debugging mode, the usual Ex commands can be used.  For example, to
  376. inspect the value of a variable: >
  377.     echo idx
  378. When inside a user function, this will print the value of the local variable
  379. "idx".  Prepend "g:" to get the value of a global variable: >
  380.     echo g:idx
  381. All commands are executed in the context of the current function or script.
  382. You can also set options, for example setting or resetting 'verbose' will show
  383. what happens, but you might want to set it just before executing the lines you
  384. are interested in: >
  385.     :set verbose=20
  386.  
  387. Commands that require updating the screen should be avoided, because their
  388. effect won't be noticed until after leaving debug mode.  For example: >
  389.     :help
  390. won't be very helpful.
  391.  
  392. There is a separate command-line history for debug mode.
  393.  
  394. The line number for a function line is relative to the start of the function.
  395. If you have trouble figuring out where you are, edit the file that defines
  396. the function in another Vim, search for the start of the function and do
  397. "99j".  Replace "99" with the line number.
  398.  
  399. Additionally, these commands can be used:
  400.                             *>cont*
  401.     cont    Continue execution until the next breakpoint is hit.
  402.                             *>quit*
  403.     quit    Abort execution.  This is like using CTRL-C, some things might
  404.         still be executed, doesn't abort everything.  Still stops at
  405.         the next breakpoint.
  406.                             *>next*
  407.     next    Execute the command and come back to debug mode when it's
  408.         finished.  This steps over user function calls and sourced
  409.         files.
  410.                             *>step*
  411.     step    Execute the command and come back to debug mode for the next
  412.         command.  This steps into called user functions and sourced
  413.         files.
  414.                             *>finish*
  415.     finish    Finish the current script or user function and come back to
  416.         debug mode for the command after the one that sourced or
  417.         called it.
  418.  
  419. About the additional commands in debug mode:
  420. - There is no command-line completion.
  421. - You can shorten them, up to a single character: "c", "n", "s" and "f".
  422. - Hitting <CR> will repeat the previous one.  When doing another command, this
  423.   is reset (because it's not clear what you want to repeat).
  424. - When you want to use the Ex command with the same name, prepend a colon:
  425.   ":cont", ":next", ":finish" (or shorter).
  426.  
  427.  
  428. DEFINING BREAKPOINTS
  429.                             *:breaka* *:breakadd*
  430. :breaka[dd] func [lnum] {name}
  431.         Set a breakpoint in a function.  Example: >
  432.             :breakadd func Explore
  433. <        Doesn't check for a valid function name, thus the breakpoint
  434.         can be set before the function is defined.
  435.  
  436. :breaka[dd] file [lnum] {name}
  437.         Set a breakpoint in a sourced file.  Example: >
  438.             :breakadd file 43 .vimrc
  439.  
  440. The [lnum] is the line number of the breakpoint.  Vim will stop at or after
  441. this line.  When omitted line 1 is used.
  442.  
  443. {name} is a pattern that is matched with the file or function name.  The
  444. pattern is like what is used for autocommands.  There must be a full match (as
  445. if the pattern starts with "^" and ends in "$").  A "*" matches any sequence
  446. of characters.  'ignorecase' is not used, but "\c" can be used in the pattern
  447. to ignore case |/\c|.  Don't include the () for the function name!
  448.  
  449. The match for sourced scripts is done against the full file name.  Examples: >
  450.     breakadd file explorer
  451. won't match, the path is missing. >
  452.     breakadd file *explorer.vim
  453. matches ".../plugin/explorer.vim" and ".../plugin/iexplorer.vim". >
  454.     breakadd file */explorer.vim
  455. matches ".../plugin/explorer.vim" only.
  456.  
  457. The match for functions is done against the name as it's shown in the output
  458. of ":function".  For local functions this means that something like "<SNR>99_"
  459. is prepended.
  460.  
  461.  
  462. DELETING BREAKPOINTS
  463.                         *:breakd* *:breakdel* *E161*
  464. :breakd[el] {nr}
  465.         Delete breakpoint {nr}.  Use |:breaklist| to see the number of
  466.         each breakpoint.
  467.  
  468. :breakd[el] func [lnum] {name}
  469.         Delete a breakpoint in a function.
  470.  
  471. :breakd[el] file [lnum] {name}
  472.         Delete a breakpoint in a sourced file.
  473.  
  474. When [lnum] is omitted, the first breakpoint in the function or file is
  475. deleted.
  476. The {name} must be exactly the same as what was typed for the ":breakadd"
  477. command.  "explorer", "*explorer.vim" and "*explorer*" are different.
  478.  
  479.  
  480. LISTING BREAKPOINTS
  481.                             *:breakl* *:breaklist*
  482. :breakl[ist]
  483.         List all breakpoints.
  484.  
  485.  vim:tw=78:ts=8:ft=help:norl:
  486.